package vista;

import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.uqbar.arena.bindings.Transformer;
import org.uqbar.commons.model.ObservableUtils;
import org.uqbar.commons.model.UserException;

import database.Tienda;

public class FechaToStringAdapter implements Transformer<LocalDate, String> {

	@Override
	public LocalDate viewToModel(String valueFromView) {
		try{
			LocalDate result = LocalDate.parse(valueFromView, DateTimeFormat.forPattern("dd/MM/yyyy"));
			return result;
		}
		catch(IllegalArgumentException exception){
			throw new UserException("Ingrese una fecha valida en formato dd/MM/yyyy");
		}
		
	}

	@Override
	public String modelToView(LocalDate valueFromModel) {
		return valueFromModel.toString("dd/MM/yyyy");
	}

	@Override
	public Class<LocalDate> getModelType() {
		return LocalDate.class;
	}

	@Override
	public Class<String> getViewType() {
		return String.class;
	}

}
